import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public void getNums(String s){
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<s.length();i++){
            char ch = s.charAt(i);
            if(ch=='['){
                sb.append('{');
            }else if(ch==']'){
                sb.append('}');
            }else if(ch=='"'){
                sb.append("'");
            } else{
                sb.append(ch);
            }
        }
        System.out.println(sb.toString());
    }


    class UnionFind{
        int[] parent;
        int[] rank;

        int count;
        public UnionFind(int n){
            parent = new int[n];
            rank = new int[n];
            count = n-1;
            for(int i=0;i<n;i++){
                parent[i]=i;
                rank[i]=1;
            }
        }

        public UnionFind(UnionFind other){
            parent = new int[other.parent.length];
            rank = new int[other.rank.length];
            count = other.count;
            for(int i=0;i<parent.length;i++){
                parent[i] = other.parent[i];
                rank[i] = other.rank[i];
            }
        }
        public int find(int index){
            if(parent[index]!=index){
                parent[index] = find(parent[index]);
            }
            return parent[index];
        }
        public void union(int p,int q){
            int a = find(p);
            int b = find(q);
            if(a==b){
                return;
            }
            if(rank[a]>rank[b]){
                union(b,a);
            }else{
                rank[b]+=rank[a];
                parent[a]=b;
                count--;
            }
        }

        public boolean isConnected(int x,int y){
            return find(x)==find(y);
        }
    }

    class Fenwick{
        int[] tree;
        int n;
        public Fenwick(int[] nums){
            this.n = nums.length;
            tree = new int[n+1];
            for(int i=1;i<=n;i++){
                tree[i] += nums[i-1];
                int next = lowBit(i)+i;
                if(next<=n){
                    tree[next] += tree[i];
                }
            }
        }

        public int lowBit(int n){
            return n&-n;
        }

        public void update(int index,int value){
            for(int i=index;i<=n;i+=lowBit(i)){
                tree[i]+=value;
            }
        }

        public int sumRange(int index){
            int ans = 0;
            while (index>0){
                ans+=tree[index];
                index-=lowBit(index);
            }
            return ans;
        }
    }

    class Trie{
        boolean isEnd;
        Trie[] children;

        Trie(){
            this.isEnd = false;
            children = new Trie[26];
        }

        public void insert(String s){
            var node = this;
            for(int i=0;i<s.length();i++){
                int index = s.charAt(i)-'a';
                if(node.children[index] == null){
                    node.children[index] = new Trie();
                }
                node = node.children[index];
            }
            node.isEnd = true;
        }

        public List<Integer> search(String s,int pos){
            var node = this;
            List<Integer> ans = new ArrayList<>();
            for(int i=pos;i<s.length();i++){
                int index = s.charAt(i)-'a';
                if(node.children[index] == null){
                    break;
                }
                node = node.children[index];
                ans.add(i-pos+1);//可以存储i-pos+1个字符
            }
            return ans;
        }
    }

    public int gcd(int a, int b) {
        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    public int lcm(int a, int b) {
        return a / gcd(a, b) * b; // 防止溢出
    }

    static final int MAX_A = 100_000;
    static final int MAX_TWOS = 5000; // 根据题目k的范围设定

    // 统计一个数中包含多少个因子2
    static int countTwos(int x) {
        int count = 0;
        while (x % 2 == 0) {
            x /= 2;
            count++;
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        int totalTwos = 0;

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            totalTwos += countTwos(a[i]);
        }

        if (totalTwos >= k) {
            System.out.println(0);
            return;
        }

        int need = k - totalTwos;

        // 动态规划：dp[i] = 达到因子2个数为i时的最小加和代价
        int[] dp = new int[MAX_TWOS + 1]; //dp[i]表示获得i个因子2的最小代价
        Arrays.fill(dp, Integer.MAX_VALUE / 2);
        dp[0] = 0;

        for (int num : a) {
            int originalTwos = countTwos(num);//重复计算包含几个2因子
            List<int[]> options = new ArrayList<>();
            options.add(new int[]{0, 0}); // 不增加的情况
            // {i,j} 想要增加i个2因子，需要j的花费
            // 预计算所有可能的增加选项
            int current = num + 1;
            while (current <= MAX_A) {
                int newTwos = countTwos(current);
                int gain = newTwos - originalTwos;
                if (gain > 0) {
                    int cost = current - num;
                    options.add(new int[]{gain, cost});
                    // 跳过一些不必要的计算，直接跳到下一个可能的2的幂次
                    current = ((current >> newTwos) + 1) << newTwos;//相当于剪枝
                } else {
                    current++;
                }
            }

            // 更新动态规划数组
            int[] newDp = Arrays.copyOf(dp, dp.length);
            for (int[] op : options) {
                int gain = op[0];//增加的2因子数量
                int cost = op[1];//花费
                for (int j = 0; j <= MAX_TWOS - gain; j++) {
                    if (dp[j] + cost < newDp[j + gain]) {
                        newDp[j + gain] = dp[j] + cost;
                    }
                }
            }
            dp = newDp;
        }

        // 寻找满足条件的最小代价
        int ans = Integer.MAX_VALUE;
        for (int i = need; i <= MAX_TWOS; i++) {
            ans = Math.min(ans, dp[i]);
        }

        System.out.println(ans == Integer.MAX_VALUE / 2 ? -1 : ans);
    }
}